﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace EnDecrypter
{
    [Serializable]
    public class ConfigData
    {
        private int modeType;//0:AES 1:DES
        private string aesKey;
        private string aesIV;
        private string desKey;
        private string desIV;
         
        public int ModeType
        {
            get
            {
                return modeType;
            }

            set
            {
                modeType = value;
            }
        }

        public string AesKey
        {
            get
            {
                return aesKey;
            }

            set
            {
                aesKey = value;
            }
        }

        public string AesIV
        {
            get
            {
                return aesIV;
            }

            set
            {
                aesIV = value;
            }
        }

        public string DesKey
        {
            get
            {
                return desKey;
            }

            set
            {
                desKey = value;
            }
        }

        public string DesIV
        {
            get
            {
                return desIV;
            }

            set
            {
                desIV = value;
            }
        }
    }
    public class Config
    {
        public static string configPath = Application.StartupPath + "\\config.xml";
        public static void XMLSerialize(ConfigData config,string filePath)
        {
            XmlSerializer xs = new XmlSerializer(typeof(ConfigData));
            Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read);
            xs.Serialize(stream, config);
            stream.Close();
        }
        public static ConfigData XMLDeserialize(string filePath)
        {
            XmlSerializer xs = new XmlSerializer(typeof(ConfigData));
            Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            ConfigData config = xs.Deserialize(stream) as ConfigData;
          
            stream.Close();

            return config;
        }
    }
}
